import urllib2
import requests
from PIL import Image
import cStringIO, StringIO
from sae.storage import Bucket, Connection


def uploadfile(srcUrl):

    f = urllib2.urlopen(srcUrl)
    data = f.read()
    tmpIm = cStringIO.StringIO(data)
    im = Image.open(tmpIm)
    c = Connection(accesskey='********', secretkey='********************', account='**********')#修改为自己的SAE信息
    bucket = c.get_bucket('img')

    imgOut = StringIO.StringIO()
    im.save(imgOut, 'jpeg')
    img_data = imgOut.getvalue()
    bucket.put_object("helloword.jpeg", img_data)

    return bucket.generate_url('helloword.jpeg')